<%-- 
    Document   : superJSP
    Created on : Nov 16, 2012, 5:19:36 PM
    Author     : mruiz
--%>

<%@page import="com.gr.uth.homework5infodisplayer.LogAPI"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Scanner"%>
<%@page import="java.io.*"%>
<%@page import="com.gr.uth.homework5infodisplayer.LogAPI"%>

<%! private int count = 0;
    private LogAPI logAPI = new LogAPI();
%>



<%  int count2 = 0;
    Integer i = new Integer(request.getParameter("counter"));
    Integer i2 = new Integer(request.getParameter("counter2"));
    System.out.println("1" + i);
    System.out.println("12" + i2);
    if (!i.equals(0) && i != null && i < 10000) {
        count = count + i;
        String logFilePath = getServletContext().getRealPath("/WEB-INF/classes/files/log.txt");
        logAPI.checkLogSizeAndClean(logFilePath);
        logAPI.writeInLog("    Global counter: " + count, logFilePath);
    }

    if (!i2.equals(0) && i2 != null && i2 < 10000) {
        count2 = count2 + i2;
        String logFilePath = getServletContext().getRealPath("/WEB-INF/classes/files/log.txt");
        logAPI.checkLogSizeAndClean(logFilePath);
        logAPI.writeInLog("    Local counter: " + count2, logFilePath);
    }

%>




<%!    public void jspInit() {
        String logFilePath = getServletContext().getRealPath("/WEB-INF/classes/files/log.txt");
        logAPI.writeInLog("\n Defining variable count = 0 as attribute. \n Servlet initialized (Init Method)", logFilePath);
    }

    public void jspDestroy() {
        String logFilePath = getServletContext().getRealPath("/WEB-INF/classes/files/log.txt");

        logAPI.writeInLog("Servlet destroyed (Destroy Method)", logFilePath);
    }
%>


<%response
            .sendRedirect("index.jsp");%>

